package network

import (
	"reflect"

	"github.com/golang/protobuf/proto"
)

type Processor interface {
	// goroutine unsafe
	Register(i *MsgInfo)
	// must goroutine safe
	//Route(msg interface{}, userData interface{}) error
	// must goroutine safe
	Unmarshal(data []byte) (interface{}, *MsgInfo, error)
	// must goroutine safe
	Marshal(msg interface{}) ([]byte, error)
}

type MsgInfo struct {
	MsgType reflect.Type
	Package string
	Method  string
	ID      uint32
}

func NewMsgInfo(msg proto.Message, protoPackage string, method string, id uint32) *MsgInfo {
	msgType := reflect.TypeOf(msg)
	m := new(MsgInfo)
	m.MsgType = msgType
	m.Package = protoPackage
	m.Method = method
	m.ID = id
	return m
}
